package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationInvoice;
import com.minimalist.common.entity.lindi.vo.tradeapplicationinvoice.LindiTradeApplicationInvoiceQueryVO;

import java.util.List;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 林地指标交易平台_交易申请发票 映射层。
 *
 * @author 11987
 * @since 2025-06-04
 */
@Mapper
public interface LindiTradeApplicationInvoiceMapper extends BaseMapper<LindiTradeApplicationInvoice>{

    /**
     * 根据交易申请发票ID查询交易申请发票
     *
     * @param tradeApplicationInvoiceId 交易申请发票ID
     * @return 交易申请发票
     */
    default LindiTradeApplicationInvoice selectTradeApplicationInvoiceByTradeApplicationInvoiceId(Long tradeApplicationInvoiceId){
        return QueryChain.of(this)
                .where(LindiTradeApplicationInvoice::getInvoiceId)
                .eq(tradeApplicationInvoiceId)
                .one();
    }

    /**
     * 分页查询交易申请发票列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationInvoice> selectPageTradeApplicationInvoiceList(LindiTradeApplicationInvoiceQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize()
                , QueryWrapper.create());
    }

    /**
     * 根据交易申请ID查询发票列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 发票列表
     */
    default List<LindiTradeApplicationInvoice> selectTradeApplicationInvoiceListByTradeApplicationId(
            Long tradeApplicationId){
        return QueryChain.of(this)
                .where(LindiTradeApplicationInvoice::getTradeApplicationId)
                .eq(tradeApplicationId)
                .orderBy(LindiTradeApplicationInvoice::getCreateTime, false)
                .list();
    }
}
